home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 980 / text0000.txt < prev   
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  69 lines

  1. John J. Maver, Jr. wrote:
  2. >     This is going to be rediculously easy to solve.  thanks  in advance!!
  3. >     I have a value entered as a string like,
  4. >     char *mystring;
  5. >     printf("Enter your age>");
  6. >     scanf("%s",&mystring);
  7.  
  8. Uh oh .....
  9.  
  10. Are you first malloc()'ing enough space for your char string?
  11.  
  12. You might try:
  13.  
  14. char mystring[5];
  15.  
  16. printf(...);
  17. scanf("%s",mystring);
  18.  
  19. >     Now I want it to be an int, so:
  20. >     myint=atoi(mystring);
  21. >     I mess around with the int:
  22. >     myint=myint+10;
  23. >
  24.  
  25. myint+=10;  // more concise     ;-)
  26.  
  27. >     And I want to turn myint back into a string.
  28. >     HOW???
  29. >     I am writing a small GUI-based prog that has a string gadget and a text
  30. > gadget.  I want to be able to take an integer from the string-gad, change it,
  31. > and then put the answer in the text-gad.
  32. >
  33.  
  34. You might try something which is often overlooked. sprintf()
  35.  
  36. char buffer[5];
  37.  
  38. sprintf(buffer, "%d", myint);
  39.  
  40. >     Thank you,
  41. >
  42.  
  43. You're welcome.
  44.  
  45. ===================================================
  46.  
  47. Jon S. Berndt
  48. Aerospace Engineer
  49. System Administration Team
  50. Space Station Training Facility
  51. GeoLogics/Hughes Training, Inc.
  52. Houston, TX
  53.  
  54. jsb@hal-pc.org
  55. jsberndt@aol.com
  56. http://www.hal-pc.org/~jsb
  57.  
  58. ===================================================
  59.